#include <REGX52.H>
#include <intrins.h>

void Delay(unsigned int xms)		//@11.0592MHz
{
	unsigned char i, j;
	while(xms)
	{
		_nop_();
		i = 2;
		j = 199;
		do
		{
			while (--j);
		} while (--i);		
		xms--;
	}
}

unsigned char LEDNum=0;
void main()
{
	P2=~0x01;
	while(1)
	{
		if(P3_1==0)
		{
			Delay(20);
			while(P3_1==0);
			Delay(20);
			
			LEDNum++;
			if(LEDNum>=8)
			{
				LEDNum=0;
			}
			P2=~(0x01<<LEDNum);
		}
		if(P3_0==0)
		{
			Delay(20);
			while(P3_0==0);
			Delay(20);	

			if(LEDNum==0)
			{
				LEDNum=7;
			}
			else
				LEDNum--;
			P2=~(0x01<<LEDNum);
		}
	}
}

/*
0000 0001   0x01<<0
0000 0010   0x01<<1
0000 0100   0x01<<2
0000 1000   0x01<<3
0001 0000   0x01<<4
0010 0000   0x01<<5
0100 0000   0x01<<6
1000 0000   0x01<<7
*/